package com.xuecheng.content.api;


import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: TeachplanController
 * Package: com.xuecheng.content.api
 * Description: 课程计划编辑接口
 *
 * @Author Endeavor-ZQB
 * @Create 2023/1/30 16:40
 * @Version 1.0
 */
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
@RestController
public class TeachplanController {

    @Autowired
    TeachplanService teachplanService;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId", name = "课程id", required = true, dataType = "Long",paramType = "path" )
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTeachPlanTreeNodes(@PathVariable Long courseId){
        return teachplanService.findTeachplayTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto teachplan){
        teachplanService.saveTeachplan(teachplan);
    }


    @ApiOperation("课程计划中章节或小节的上移")
    @PostMapping("/teachplan/moveup/{teachPlanId}")
    public void moveupTeachplan(@PathVariable Long teachPlanId){

         teachplanService.upDown("moveup",teachPlanId);
    }

    @ApiOperation("课程计划中章节或小节的下移")
    @PostMapping("/teachplan/movedown/{teachPlanId}")
    public void movedownTeachplan(@PathVariable @Validated Long teachPlanId){

        teachplanService.upDown("movedown",teachPlanId);
    }

    @ApiOperation("删除课程计划中的小节")
    @ApiImplicitParam(value = "teachplanId", name = "课程计划id", required = true, dataType = "Long",paramType = "path" )
    @DeleteMapping("/teachplan/{teachplanId}")
    public void deleteTeachplanById(@PathVariable Long teachplanId){
        teachplanService.deleteTeachplanById(teachplanId);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "课程计划和媒资信息解除绑定")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void delAssociationMedia(@PathVariable Long teachPlanId,@PathVariable String mediaId){
    teachplanService.delAassociationMedia(teachPlanId,mediaId);
    }


}
